#include <iostream>
using namespace std;
const int N = 500010;
struct edge {
  int to, next;
} e[N << 1];
int head[N], tot;

void add(int x, int y) {
  e[++tot].to = y;
  e[tot].next = head[x];
  head[x] = tot;
}

int depth[N], fa[N][22], lg[N];
void dfs(int now, int fath) {
  fa[now][0] = fath;
  depth[now] = depth[fath] + 1;
  for (int i = 1; i <= lg[depth[now]]; ++i)
    fa[now][i] = fa[fa[now][i - 1]][i - 1];
  for (int i = head[now]; i; i = e[i].next)
    if (e[i].to != fath) dfs(e[i].to, now);
}
int LCA(int x, int y) {
  if (depth[x] < depth[y]) swap(x, y);
  while (depth[x] > depth[y]) x = fa[x][lg[depth[x] - depth[y]] - 1];
  if (x == y) return x;
  for (int k = lg[depth[x]] - 1; k >= 0; --k)
    if (fa[x][k] != fa[y][k]) x = fa[x][k], y = fa[y][k];
  return fa[x][0];
}
int main() {
  int n, m, s;
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 1; i <= n - 1; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  for (int i = 1; i <= n; ++i) lg[i] = lg[i - 1] + (1 << lg[i - 1] == i);
  dfs(s, 0);
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    printf("%d\n", LCA(x, y));
  }
}
